#include<stdio.h>

#define INF 65536
#define MAX 7

double g [][MAX] = 
{{0, 28, INF, INF, INF, 10, INF},
 {28, 0, 16, INF, INF, INF, 14},
 {INF, 16, 0, 12, INF, INF, INF},
 {INF, INF, 12, 0, 22, INF, 18},
 {INF, INF, INF, 22, 0, 25, 24},
 {10, INF, INF, INF, 25, 0, INF},
 {INF, 14, INF, 18, 24, INF, 0}};

void prim (double g[][MAX], int start)
{
	int i, j, k;
	double min;
	int closest[MAX];
	double lowcost[MAX];
	
	for (i = 0; i < MAX; ++i) {
		closest[i] = start;
		lowcost[i] = g[start][i];
	}

	for (i = 1; i < MAX; ++i) {
		min = INF;
		
		for (j = 0; j < MAX; ++j)
			if (lowcost[j] != 0 && lowcost[j] < min) {
				min = lowcost[j]; k = j;
			}
		printf("weight of edge(%d, %d) is %f\n", closest[k], k, min);
		lowcost[k] = 0;

		for (j = 0; j < MAX; ++j)
			if (lowcost[j] != 0 && g[k][j] < lowcost[j]) {
				lowcost[j] = g[k][j];
				closest[j] = k;
			}
	}

}

int main() 
{
	prim(g, 0);
	return 0;
}
